.class public Lcom/qiniu/utils/InputStreamAt;
.super Ljava/lang/Object;
.source "InputStreamAt.java"

# interfaces
.implements Ljava/io/Closeable;


# instance fields
.field private mClosed:Z

.field private mCrc32:J

.field private mData:[B

.field private mDelWhenClose:Z

.field private mFileStream:Ljava/io/RandomAccessFile;

.field private mLength:J

.field private mTmpFile:Ljava/io/File;


# direct methods
.method public constructor <init>(Ljava/io/File;)V
    .registers 3
    .param p1, "file"    # Ljava/io/File;

    .prologue
    .line 44
    const/4 v0, 0x0

    invoke-direct {p0, p1, v0}, Lcom/qiniu/utils/InputStreamAt;-><init>(Ljava/io/File;Z)V

    .line 45
    return-void
.end method

.method public constructor <init>(Ljava/io/File;Z)V
    .registers 7
    .param p1, "file"    # Ljava/io/File;
    .param p2, "delWhenClose"    # Z

    .prologue
    const-wide/16 v2, -0x1

    .line 47
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 19
    const/4 v1, 0x0

    iput-boolean v1, p0, Lcom/qiniu/utils/InputStreamAt;->mDelWhenClose:Z

    .line 20
    iput-wide v2, p0, Lcom/qiniu/utils/InputStreamAt;->mCrc32:J

    .line 21
    iput-wide v2, p0, Lcom/qiniu/utils/InputStreamAt;->mLength:J

    .line 48
    iput-object p1, p0, Lcom/qiniu/utils/InputStreamAt;->mTmpFile:Ljava/io/File;

    .line 49
    iput-boolean p2, p0, Lcom/qiniu/utils/InputStreamAt;->mDelWhenClose:Z

    .line 51
    :try_start_10
    new-instance v1, Ljava/io/RandomAccessFile;

    iget-object v2, p0, Lcom/qiniu/utils/InputStreamAt;->mTmpFile:Ljava/io/File;

    const-string v3, "r"

    invoke-direct {v1, v2, v3}, Ljava/io/RandomAccessFile;-><init>(Ljava/io/File;Ljava/lang/String;)V

    iput-object v1, p0, Lcom/qiniu/utils/InputStreamAt;->mFileStream:Ljava/io/RandomAccessFile;
    :try_end_1b
    .catch Ljava/io/FileNotFoundException; {:try_start_10 .. :try_end_1b} :catch_1c

    .line 55
    :goto_1b
    return-void

    .line 52
    :catch_1c
    move-exception v0

    .line 53
    .local v0, "e":Ljava/io/FileNotFoundException;
    invoke-virtual {v0}, Ljava/io/FileNotFoundException;->printStackTrace()V

    goto :goto_1b
.end method

.method public constructor <init>([B)V
    .registers 6
    .param p1, "data"    # [B

    .prologue
    const-wide/16 v2, -0x1

    .line 57
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 19
    const/4 v0, 0x0

    iput-boolean v0, p0, Lcom/qiniu/utils/InputStreamAt;->mDelWhenClose:Z

    .line 20
    iput-wide v2, p0, Lcom/qiniu/utils/InputStreamAt;->mCrc32:J

    .line 21
    iput-wide v2, p0, Lcom/qiniu/utils/InputStreamAt;->mLength:J

    .line 58
    iput-object p1, p0, Lcom/qiniu/utils/InputStreamAt;->mData:[B

    .line 59
    return-void
.end method

.method static synthetic access$000(Lcom/qiniu/utils/InputStreamAt;)Z
    .registers 2
    .param p0, "x0"    # Lcom/qiniu/utils/InputStreamAt;

    .prologue
    .line 13
    iget-boolean v0, p0, Lcom/qiniu/utils/InputStreamAt;->mClosed:Z

    return v0
.end method

.method public static fromFile(Ljava/io/File;)Lcom/qiniu/utils/InputStreamAt;
    .registers 2
    .param p0, "f"    # Ljava/io/File;

    .prologue
    .line 35
    new-instance v0, Lcom/qiniu/utils/InputStreamAt;

    invoke-direct {v0, p0}, Lcom/qiniu/utils/InputStreamAt;-><init>(Ljava/io/File;)V

    .line 36
    .local v0, "isa":Lcom/qiniu/utils/InputStreamAt;
    return-object v0
.end method

.method public static fromInputStream(Landroid/content/Context;Ljava/io/InputStream;)Lcom/qiniu/utils/InputStreamAt;
    .registers 5
    .param p0, "context"    # Landroid/content/Context;
    .param p1, "is"    # Ljava/io/InputStream;

    .prologue
    .line 28
    invoke-static {p0, p1}, Lcom/qiniu/utils/InputStreamAt;->storeToFile(Landroid/content/Context;Ljava/io/InputStream;)Ljava/io/File;

    move-result-object v0

    .line 29
    .local v0, "file":Ljava/io/File;
    if-nez v0, :cond_8

    const/4 v1, 0x0

    .line 31
    :goto_7
    return-object v1

    .line 30
    :cond_8
    new-instance v1, Lcom/qiniu/utils/InputStreamAt;

    const/4 v2, 0x1

    invoke-direct {v1, v0, v2}, Lcom/qiniu/utils/InputStreamAt;-><init>(Ljava/io/File;Z)V

    .line 31
    .local v1, "isa":Lcom/qiniu/utils/InputStreamAt;
    goto :goto_7
.end method

.method public static fromString(Ljava/lang/String;)Lcom/qiniu/utils/InputStreamAt;
    .registers 3
    .param p0, "str"    # Ljava/lang/String;

    .prologue
    .line 40
    new-instance v0, Lcom/qiniu/utils/InputStreamAt;

    invoke-virtual {p0}, Ljava/lang/String;->getBytes()[B

    move-result-object v1

    invoke-direct {v0, v1}, Lcom/qiniu/utils/InputStreamAt;-><init>([B)V

    return-object v0
.end method

.method public static getSDPath(Landroid/content/Context;)Ljava/io/File;
    .registers 5
    .param p0, "context"    # Landroid/content/Context;

    .prologue
    .line 232
    invoke-virtual {p0}, Landroid/content/Context;->getCacheDir()Ljava/io/File;

    move-result-object v1

    .line 233
    .local v1, "sdDir":Ljava/io/File;
    invoke-static {}, Landroid/os/Environment;->getExternalStorageState()Ljava/lang/String;

    move-result-object v2

    const-string v3, "mounted"

    .line 234
    invoke-virtual {v2, v3}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v0

    .line 235
    .local v0, "sdCardExist":Z
    if-eqz v0, :cond_14

    .line 236
    invoke-static {}, Landroid/os/Environment;->getExternalStorageDirectory()Ljava/io/File;

    move-result-object v1

    .line 238
    :cond_14
    return-object v1
.end method

.method protected static storeToFile(Landroid/content/Context;Ljava/io/InputStream;)Ljava/io/File;
    .registers 10
    .param p0, "context"    # Landroid/content/Context;
    .param p1, "is"    # Ljava/io/InputStream;

    .prologue
    .line 106
    :try_start_0
    invoke-static {p0}, Lcom/qiniu/utils/InputStreamAt;->getSDPath(Landroid/content/Context;)Ljava/io/File;

    move-result-object v5

    .line 107
    .local v5, "outputDir":Ljava/io/File;
    const-string v6, "qiniu-"

    const-string v7, ""

    invoke-static {v6, v7, v5}, Ljava/io/File;->createTempFile(Ljava/lang/String;Ljava/lang/String;Ljava/io/File;)Ljava/io/File;

    move-result-object v3

    .line 108
    .local v3, "f":Ljava/io/File;
    new-instance v4, Ljava/io/FileOutputStream;

    invoke-direct {v4, v3}, Ljava/io/FileOutputStream;-><init>(Ljava/io/File;)V

    .line 109
    .local v4, "os":Ljava/io/OutputStream;
    const/high16 v6, 0x10000

    new-array v0, v6, [B

    .line 111
    .local v0, "buffer":[B
    :goto_15
    invoke-virtual {p1, v0}, Ljava/io/InputStream;->read([B)I

    move-result v1

    .local v1, "bytesRead":I
    const/4 v6, -0x1

    if-eq v1, v6, :cond_27

    .line 112
    const/4 v6, 0x0

    invoke-virtual {v4, v0, v6, v1}, Ljava/io/OutputStream;->write([BII)V
    :try_end_20
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_20} :catch_21

    goto :goto_15

    .line 117
    .end local v0    # "buffer":[B
    .end local v1    # "bytesRead":I
    .end local v3    # "f":Ljava/io/File;
    .end local v4    # "os":Ljava/io/OutputStream;
    .end local v5    # "outputDir":Ljava/io/File;
    :catch_21
    move-exception v2

    .line 118
    .local v2, "e":Ljava/io/IOException;
    invoke-virtual {v2}, Ljava/io/IOException;->printStackTrace()V

    .line 119
    const/4 v3, 0x0

    .end local v2    # "e":Ljava/io/IOException;
    :cond_26
    :goto_26
    return-object v3

    .line 114
    .restart local v0    # "buffer":[B
    .restart local v1    # "bytesRead":I
    .restart local v3    # "f":Ljava/io/File;
    .restart local v4    # "os":Ljava/io/OutputStream;
    .restart local v5    # "outputDir":Ljava/io/File;
    :cond_27
    if-eqz v4, :cond_2c

    :try_start_29
    invoke-virtual {v4}, Ljava/io/OutputStream;->close()V

    .line 115
    :cond_2c
    if-eqz p1, :cond_26

    invoke-virtual {p1}, Ljava/io/InputStream;->close()V
    :try_end_31
    .catch Ljava/io/IOException; {:try_start_29 .. :try_end_31} :catch_21

    goto :goto_26
.end method


# virtual methods
.method public declared-synchronized close()V
    .registers 3

    .prologue
    .line 164
    monitor-enter p0

    :try_start_1
    iget-boolean v1, p0, Lcom/qiniu/utils/InputStreamAt;->mClosed:Z
    :try_end_3
    .catchall {:try_start_1 .. :try_end_3} :catchall_21

    if-eqz v1, :cond_7

    .line 178
    :cond_5
    :goto_5
    monitor-exit p0

    return-void

    .line 165
    :cond_7
    const/4 v1, 0x1

    :try_start_8
    iput-boolean v1, p0, Lcom/qiniu/utils/InputStreamAt;->mClosed:Z

    .line 167
    iget-object v1, p0, Lcom/qiniu/utils/InputStreamAt;->mFileStream:Ljava/io/RandomAccessFile;
    :try_end_c
    .catchall {:try_start_8 .. :try_end_c} :catchall_21

    if-eqz v1, :cond_13

    .line 169
    :try_start_e
    iget-object v1, p0, Lcom/qiniu/utils/InputStreamAt;->mFileStream:Ljava/io/RandomAccessFile;

    invoke-virtual {v1}, Ljava/io/RandomAccessFile;->close()V
    :try_end_13
    .catch Ljava/io/IOException; {:try_start_e .. :try_end_13} :catch_24
    .catchall {:try_start_e .. :try_end_13} :catchall_21

    .line 175
    :cond_13
    :goto_13
    :try_start_13
    iget-object v1, p0, Lcom/qiniu/utils/InputStreamAt;->mTmpFile:Ljava/io/File;

    if-eqz v1, :cond_5

    iget-boolean v1, p0, Lcom/qiniu/utils/InputStreamAt;->mDelWhenClose:Z

    if-eqz v1, :cond_5

    .line 176
    iget-object v1, p0, Lcom/qiniu/utils/InputStreamAt;->mTmpFile:Ljava/io/File;

    invoke-virtual {v1}, Ljava/io/File;->delete()Z
    :try_end_20
    .catchall {:try_start_13 .. :try_end_20} :catchall_21

    goto :goto_5

    .line 164
    :catchall_21
    move-exception v1

    monitor-exit p0

    throw v1

    .line 170
    :catch_24
    move-exception v0

    .line 171
    .local v0, "e":Ljava/io/IOException;
    :try_start_25
    invoke-virtual {v0}, Ljava/io/IOException;->printStackTrace()V
    :try_end_28
    .catchall {:try_start_25 .. :try_end_28} :catchall_21

    goto :goto_13
.end method

.method public crc32()J
    .registers 13

    .prologue
    .line 69
    iget-wide v8, p0, Lcom/qiniu/utils/InputStreamAt;->mCrc32:J

    const-wide/16 v10, 0x0

    cmp-long v8, v8, v10

    if-ltz v8, :cond_b

    iget-wide v8, p0, Lcom/qiniu/utils/InputStreamAt;->mCrc32:J

    .line 83
    :goto_a
    return-wide v8

    .line 70
    :cond_b
    new-instance v1, Ljava/util/zip/CRC32;

    invoke-direct {v1}, Ljava/util/zip/CRC32;-><init>()V

    .line 71
    .local v1, "crc32":Ljava/util/zip/CRC32;
    const-wide/16 v4, 0x0

    .line 72
    .local v4, "index":J
    const/high16 v0, 0x20000

    .line 73
    .local v0, "blockSize":I
    invoke-virtual {p0}, Lcom/qiniu/utils/InputStreamAt;->length()J

    move-result-wide v6

    .line 74
    .local v6, "length":J
    :goto_18
    cmp-long v8, v4, v6

    if-gez v8, :cond_37

    .line 75
    sub-long v8, v6, v4

    int-to-long v10, v0

    cmp-long v8, v8, v10

    if-ltz v8, :cond_2d

    move v3, v0

    .line 77
    .local v3, "size":I
    :goto_24
    invoke-virtual {p0, v4, v5, v3}, Lcom/qiniu/utils/InputStreamAt;->read(JI)[B

    move-result-object v2

    .line 78
    .local v2, "data":[B
    if-nez v2, :cond_31

    const-wide/16 v8, -0x1

    goto :goto_a

    .line 75
    .end local v2    # "data":[B
    .end local v3    # "size":I
    :cond_2d
    sub-long v8, v6, v4

    long-to-int v3, v8

    goto :goto_24

    .line 79
    .restart local v2    # "data":[B
    .restart local v3    # "size":I
    :cond_31
    invoke-virtual {v1, v2}, Ljava/util/zip/CRC32;->update([B)V

    .line 80
    int-to-long v8, v3

    add-long/2addr v4, v8

    .line 81
    goto :goto_18

    .line 82
    .end local v2    # "data":[B
    .end local v3    # "size":I
    :cond_37
    invoke-virtual {v1}, Ljava/util/zip/CRC32;->getValue()J

    move-result-wide v8

    iput-wide v8, p0, Lcom/qiniu/utils/InputStreamAt;->mCrc32:J

    .line 83
    iget-wide v8, p0, Lcom/qiniu/utils/InputStreamAt;->mCrc32:J

    goto :goto_a
.end method

.method protected fileStreamRead(JI)[B
    .registers 9
    .param p1, "offset"    # J
    .param p3, "length"    # I
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 142
    iget-object v3, p0, Lcom/qiniu/utils/InputStreamAt;->mFileStream:Ljava/io/RandomAccessFile;

    if-nez v3, :cond_6

    const/4 v0, 0x0

    .line 159
    :cond_5
    :goto_5
    return-object v0

    .line 143
    :cond_6
    new-array v0, p3, [B

    .line 146
    .local v0, "data":[B
    const/4 v2, 0x0

    .line 147
    .local v2, "totalRead":I
    monitor-enter v0

    .line 148
    :try_start_a
    iget-object v3, p0, Lcom/qiniu/utils/InputStreamAt;->mFileStream:Ljava/io/RandomAccessFile;

    invoke-virtual {v3, p1, p2}, Ljava/io/RandomAccessFile;->seek(J)V

    .line 150
    :cond_f
    iget-object v3, p0, Lcom/qiniu/utils/InputStreamAt;->mFileStream:Ljava/io/RandomAccessFile;

    invoke-virtual {v3, v0, v2, p3}, Ljava/io/RandomAccessFile;->read([BII)I

    move-result v1

    .line 151
    .local v1, "read":I
    if-gtz v1, :cond_21

    .line 154
    :goto_17
    monitor-exit v0
    :try_end_18
    .catchall {:try_start_a .. :try_end_18} :catchall_25

    .line 156
    array-length v3, v0

    if-eq v2, v3, :cond_5

    .line 157
    const/4 v3, 0x0

    invoke-static {v0, v3, v2}, Ljava/util/Arrays;->copyOfRange([BII)[B

    move-result-object v0

    goto :goto_5

    .line 152
    :cond_21
    add-int/2addr v2, v1

    .line 153
    if-gt p3, v2, :cond_f

    goto :goto_17

    .line 154
    .end local v1    # "read":I
    :catchall_25
    move-exception v3

    :try_start_26
    monitor-exit v0
    :try_end_27
    .catchall {:try_start_26 .. :try_end_27} :catchall_25

    throw v3
.end method

.method public getCrc32(JI)J
    .registers 9
    .param p1, "offset"    # J
    .param p3, "length"    # I

    .prologue
    .line 62
    new-instance v0, Ljava/util/zip/CRC32;

    invoke-direct {v0}, Ljava/util/zip/CRC32;-><init>()V

    .line 63
    .local v0, "crc32":Ljava/util/zip/CRC32;
    invoke-virtual {p0, p1, p2, p3}, Lcom/qiniu/utils/InputStreamAt;->read(JI)[B

    move-result-object v1

    .line 64
    .local v1, "data":[B
    invoke-virtual {v0, v1}, Ljava/util/zip/CRC32;->update([B)V

    .line 65
    invoke-virtual {v0}, Ljava/util/zip/CRC32;->getValue()J

    move-result-wide v2

    return-wide v2
.end method

.method public length()J
    .registers 7

    .prologue
    .line 87
    iget-wide v2, p0, Lcom/qiniu/utils/InputStreamAt;->mLength:J

    const-wide/16 v4, 0x0

    cmp-long v1, v2, v4

    if-ltz v1, :cond_b

    iget-wide v2, p0, Lcom/qiniu/utils/InputStreamAt;->mLength:J

    .line 101
    :goto_a
    return-wide v2

    .line 88
    :cond_b
    iget-object v1, p0, Lcom/qiniu/utils/InputStreamAt;->mData:[B

    if-eqz v1, :cond_18

    .line 89
    iget-object v1, p0, Lcom/qiniu/utils/InputStreamAt;->mData:[B

    array-length v1, v1

    int-to-long v2, v1

    iput-wide v2, p0, Lcom/qiniu/utils/InputStreamAt;->mLength:J

    .line 90
    iget-wide v2, p0, Lcom/qiniu/utils/InputStreamAt;->mLength:J

    goto :goto_a

    .line 93
    :cond_18
    iget-object v1, p0, Lcom/qiniu/utils/InputStreamAt;->mFileStream:Ljava/io/RandomAccessFile;

    if-eqz v1, :cond_2b

    .line 95
    :try_start_1c
    iget-object v1, p0, Lcom/qiniu/utils/InputStreamAt;->mFileStream:Ljava/io/RandomAccessFile;

    invoke-virtual {v1}, Ljava/io/RandomAccessFile;->length()J

    move-result-wide v2

    iput-wide v2, p0, Lcom/qiniu/utils/InputStreamAt;->mLength:J

    .line 96
    iget-wide v2, p0, Lcom/qiniu/utils/InputStreamAt;->mLength:J
    :try_end_26
    .catch Ljava/io/IOException; {:try_start_1c .. :try_end_26} :catch_27

    goto :goto_a

    .line 97
    :catch_27
    move-exception v0

    .line 98
    .local v0, "e":Ljava/io/IOException;
    invoke-virtual {v0}, Ljava/io/IOException;->printStackTrace()V

    .line 101
    .end local v0    # "e":Ljava/io/IOException;
    :cond_2b
    const-wide/16 v2, -0x1

    goto :goto_a
.end method

.method public read([B)I
    .registers 3
    .param p1, "data"    # [B
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 181
    iget-object v0, p0, Lcom/qiniu/utils/InputStreamAt;->mFileStream:Ljava/io/RandomAccessFile;

    invoke-virtual {v0, p1}, Ljava/io/RandomAccessFile;->read([B)I

    move-result v0

    return v0
.end method

.method public read(JI)[B
    .registers 11
    .param p1, "offset"    # J
    .param p3, "length"    # I

    .prologue
    const/4 v2, 0x0

    .line 124
    iget-boolean v3, p0, Lcom/qiniu/utils/InputStreamAt;->mClosed:Z

    if-eqz v3, :cond_7

    move-object v1, v2

    .line 138
    :goto_6
    return-object v1

    .line 126
    :cond_7
    :try_start_7
    iget-object v3, p0, Lcom/qiniu/utils/InputStreamAt;->mFileStream:Ljava/io/RandomAccessFile;

    if-eqz v3, :cond_10

    .line 127
    invoke-virtual {p0, p1, p2, p3}, Lcom/qiniu/utils/InputStreamAt;->fileStreamRead(JI)[B

    move-result-object v1

    goto :goto_6

    .line 129
    :cond_10
    iget-object v3, p0, Lcom/qiniu/utils/InputStreamAt;->mData:[B

    if-eqz v3, :cond_22

    .line 130
    new-array v1, p3, [B

    .line 131
    .local v1, "ret":[B
    iget-object v3, p0, Lcom/qiniu/utils/InputStreamAt;->mData:[B

    long-to-int v4, p1

    const/4 v5, 0x0

    invoke-static {v3, v4, v1, v5, p3}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
    :try_end_1d
    .catch Ljava/io/IOException; {:try_start_7 .. :try_end_1d} :catch_1e

    goto :goto_6

    .line 134
    .end local v1    # "ret":[B
    :catch_1e
    move-exception v0

    .line 135
    .local v0, "e":Ljava/io/IOException;
    invoke-virtual {v0}, Ljava/io/IOException;->printStackTrace()V

    .end local v0    # "e":Ljava/io/IOException;
    :cond_22
    move-object v1, v2

    .line 138
    goto :goto_6
.end method

.method public toHttpEntity(JILcom/qiniu/auth/Client$ClientExecutor;)Lorg/apache/http/HttpEntity;
    .registers 14
    .param p1, "offset"    # J
    .param p3, "length"    # I
    .param p4, "client"    # Lcom/qiniu/auth/Client$ClientExecutor;

    .prologue
    .line 185
    move-object v6, p0

    .line 186
    .local v6, "input":Lcom/qiniu/utils/InputStreamAt;
    new-instance v1, Lcom/qiniu/utils/InputStreamAt$1;

    move-object v2, p0

    move v3, p3

    move-wide v4, p1

    move-object v7, p4

    invoke-direct/range {v1 .. v7}, Lcom/qiniu/utils/InputStreamAt$1;-><init>(Lcom/qiniu/utils/InputStreamAt;IJLcom/qiniu/utils/InputStreamAt;Lcom/qiniu/auth/Client$ClientExecutor;)V

    return-object v1
.end method
